package com.journaldev.spring.util;

import java.beans.PropertyEditorSupport;

import com.journaldev.spring.model.Patient;
import com.journaldev.spring.service.PatientService;

public class SimplePatientEditor extends PropertyEditorSupport {
	private PatientService patientService;

    public SimplePatientEditor(PatientService service){
        this.patientService = service;
    }
    
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
    	Patient patient = null;
        try {
            Integer id = Integer.parseInt(text);
            patient = patientService.getPatientById(id);
            System.out.println("patient name:" + patient.getName());
        } catch (NumberFormatException ex) {
            System.out.println("Department will be null");
        }
        setValue(patient);
    }
}
